<?php
/**
 * Created by PhpStorm.
 * User: lixy
 * Date: 2016/10/9
 * Time: 9:51
 */

namespace app\controllers;


use app\librarys\BaseController;
use app\librarys\Fanso2oInteface;
use app\librarys\Tools;

class TestController extends BaseController
{
    public function actionT1()
    {
      $x=1477843200;
        echo date('Y-m-d',$x);
       exit;
    }
    public function actionT2()
    {
        echo  Tools::var_dump_out( Fanso2oInteface::queryShopByTag('506'));
        exit;
    }
    public function actionT3()
    {
        //标签列表
       $tagList= Fanso2oInteface::queryTagOfShop();
        echo "标签列表:<br>";
        echo  Tools::var_dump_out( $tagList);
       //站点列表
        $shopList=Fanso2oInteface::queryShopByTag($tagList[0]->tagId);
        echo "站点列表:<br>";
        echo  Tools::var_dump_out( $shopList);
        //获取活动列表
        $activityList=[];
        foreach($shopList as $item){
            try {
                $activityList[]=[
                    'shopId'=>$item->shopId,
                    'info'=>Fanso2oInteface::getLatestActivity($item->shopId),
                ];
            }catch(\Exception $e){
                //忽略没有有效活动的站点
            }
        }
        echo "活动列表:<br>";
        echo Tools::var_dump_out($activityList);

        //产品列表
        $goodsList=[];
        foreach($activityList as $item){
            $goods['amount']=$item['info']->amount;
            $goods['shopId']=$item['shopId'];
            $goods['info']=Fanso2oInteface::activityResource($item['info']->activityId)[0];
            $goodsList[]=$goods;
        }
        echo "产品列表<br/>";
        echo Tools::var_dump_out($goodsList);exit;
        foreach($goodsList as $item){
//            echo Tools::var_dump_out($item['info']);exit;
            echo "<br/>名称: ".$item['info']->title;
            echo "<br/>领取时间至: ".date('Y-m-d',$item['info']->dateValidTo);
            echo "<br/>领取链接:<a href='http://m.fanso2o.com/shop/ ".$item['shopId']."'>点击领取</a>";
            echo "<br/>品牌: ".$item['info']->brands;
            echo "<br/>库存: ".$item['amount'];
            echo "<br/>图片: <img src='".$item['info']->picBg."'/>";
            echo "<br/>简介: ".$item['info']->description;
            echo "<hr/><br/>";
        }
        exit;
    }
    public function actionT4()
    {
        //站点列表
        $shopList=Fanso2oInteface::queryShopList();

        //获取活动列表

        $activityList=[];
        foreach($shopList as $item){
            try {
                $activityList[]=[
                    'shopId'=>$item->shopId,
                    'info'=>Fanso2oInteface::getLatestActivity($item->shopId),
                ];
            }catch(\Exception $e){
                //忽略没有有效活动的站点
            }
        }
//        echo Tools::var_dump_out($activityList);exit;
        //产品列表
        $goodsList=[];
        foreach($activityList as $item){
            $goods['amount']=$item['info']->amount;
            $goods['shopId']=$item['shopId'];
            $goods['info']=Fanso2oInteface::activityResource($item['info']->activityId)[0];
            $goodsList[]=$goods;
        }
        echo "产品列表<br/>";
//        echo Tools::var_dump_out($goodsList);exit;
        foreach($goodsList as $item){
//            echo Tools::var_dump_out($item['info']);exit;
            echo "<br/>名称: ".$item['info']->title;
            echo "<br/>领取链接:<a href='http://m.fanso2o.com/shop/ ".$item['shopId']."'>点击领取</a>";
            echo "<br/>品牌: ".$item['info']->brands;
            echo "<br/>库存: ".$item['amount'];
            echo "<br/>图片: <img src='http://".$item['info']->picBg."'/>";
            echo "<br/>简介: ".$item['info']->description;
            echo "<hr/><br/>";
        }
        exit;
    }
}